package com.itheima.aop;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Slf4j
@Component
@Aspect
public class RecordTimeAspect {
    @Around("execution(* com.itheima.service.impl.*.*(..))")
    public Object recordTime(ProceedingJoinPoint pjp) throws Throwable {
        //1.获取开始时间
        long begin=System.currentTimeMillis();

        //2.执行目标方法
        Object result=pjp.proceed();

        //3.获取结束时间
        long end=System.currentTimeMillis();
        log.info("耗时：{}ms",end-begin);

        return result;
    }
}
